package com.mindao.app.weixin.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mindao.app.common.spring.controller.BaseController;
import com.mindao.app.common.spring.model.BaseModel;
import com.mindao.app.common.spring.page.Pagination;
import com.mindao.app.common.spring.service.util.JsonResult;
import com.mindao.app.weixin.model.WxmpUserInfo;
import com.mindao.utils.config.EaCommonUtils;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：
/*
/* 创 建 人：李国才
/* 创建时间：2016年6月26日 下午8:24:43 	
 **/
@Controller
@RequestMapping("/weixin/wxmpuserinfo")
public class WxmpUserInfoController extends BaseController<WxmpUserInfo> {
	private final Logger log = LoggerFactory.getLogger(WxmpUserInfoController.class);
	/**
	 * 进入列表查询页面
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception
	 */
	@RequestMapping   
	public String search(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		return  rtnDefault(request, response, session, rhs);
	}
	/**
	 * 加载分页列表数据
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( method = RequestMethod.POST)
	public String searchPageAjax(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		String className =  getModelClass().getName();
		String sql="from " + className + "   where status>"+BaseModel.STATUS_REMOVED;
		Map map=request.getParameterMap();
        //按页面提交参数分页查询 
		Pagination p= getPagination( );
		List list=null;
		try {
			list = baseService.findByHQLPage(sql, map, "", getParameter("orderBy"),p );
			rhs.addAttribute("dataList", list);
			rhs.addAttribute("pagination", p);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage(),e);
		}
		return rtnDefault(request, response, session, rhs);
	}
	
	@ResponseBody
	@RequestMapping  ( method = RequestMethod.POST) 
	public JsonResult getRemark(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,String uuid) throws Exception {
		WxmpUserInfo  fan=(WxmpUserInfo)EaCommonUtils.getObjectByUuid(uuid, "WxmpUserInfo");
		JsonResult jrSucc=new JsonResult(JsonResult.SUCCESS,"修改备注成功",fan.getRemark());
		return jrSucc;
	}
	
	@ResponseBody
	@RequestMapping  ( method = RequestMethod.POST) 
	public JsonResult submitRemark(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,String uuid) throws Exception {
		WxmpUserInfo  fan=(WxmpUserInfo)EaCommonUtils.getObjectByUuid(uuid, "WxmpUserInfo");
		fan.setRemark(getpara("myremark"));
		baseService.update(fan);
		JsonResult jrSucc=new JsonResult(JsonResult.SUCCESS,"修改备注成功");
		return jrSucc;
	}
}
